﻿Imports System.Data
Imports System.Data.SqlClient
Imports Sistema_InformacionNaviera.BE
Imports Sistema_InformacionNavier.UTIL

Public Class GeneralDALC
    Public Function ListaGeneral(ByVal objGeneralBE As GeneralBE) As List(Of GeneralBE)

        Dim sqlListar As String
        Dim objListadoGeneral As New List(Of GeneralBE)
        Dim objGenerBE As GeneralBE = Nothing
        Dim arrSqlParameter(3) As SqlParameter
        Dim ds As DataSet
        Dim dt As DataTable

        Dim objDatos As New AccesoDatos()
        Dim blnExito As Boolean
        Dim strMensaje As String = String.Empty
        Dim intI As Integer = 0

        Try

            sqlListar = "up_ListaGral"

            If objGeneralBE.Param1 Is Nothing Then
                objGeneralBE.Param1 = ""
            End If

            If IsDBNull(objGeneralBE.Param1) Then
                objGeneralBE.Param1 = ""
            End If

            If objGeneralBE.Param2 Is Nothing Then
                objGeneralBE.Param2 = ""
            End If

            If IsDBNull(objGeneralBE.Param2) Then
                objGeneralBE.Param2 = ""
            End If

            If objGeneralBE.Usu Is Nothing Then
                objGeneralBE.Usu = ""
            End If

            If IsDBNull(objGeneralBE.Usu) Then
                objGeneralBE.Usu = ""
            End If


            arrSqlParameter(0) = New SqlParameter("@TIPO", System.Data.SqlDbType.VarChar)
            arrSqlParameter(0).Value = objGeneralBE.Codigo

            arrSqlParameter(1) = New SqlParameter("@PAR1", System.Data.SqlDbType.VarChar)
            arrSqlParameter(1).Value = objGeneralBE.Param1

            arrSqlParameter(2) = New SqlParameter("@PAR2", System.Data.SqlDbType.VarChar)
            arrSqlParameter(2).Value = objGeneralBE.Param2

            arrSqlParameter(3) = New SqlParameter("@USU", System.Data.SqlDbType.VarChar)
            arrSqlParameter(3).Value = objGeneralBE.Usu

            objListadoGeneral = New List(Of GeneralBE)()


            ds = objDatos.DevuelveDataSet(sqlListar, blnExito, strMensaje, arrSqlParameter)
            If ds.Tables.Count > 0 Then
                dt = ds.Tables(0)

                If dt.Rows.Count > 0 Then

                    While intI < dt.Rows.Count
                        objGenerBE = New GeneralBE()
                        objGenerBE.Codigo = dt.Rows(intI).ItemArray(0).ToString
                        objGenerBE.Descripcion = dt.Rows(intI).ItemArray(1).ToString
                        intI = intI + 1

                        objListadoGeneral.Add(objGenerBE)
                    End While
                End If
            Else
                objListadoGeneral = Nothing
            End If
        Catch ex As Exception
            MsgBox(ex.Message, vbCritical, "Error del sistema")
            Return Nothing
            Exit Function
        End Try

        Return objListadoGeneral
    End Function



End Class
